-- funcao de redesenho de cada ciclo de animacao
function redraw()
    local filename = "../webservice/eliminatorias2_jogos"
    file, err = io.open(filename, "r")
    if (err == nil) then
        canvas:attrFont('vera',26,'bold')
        local i = 0
        for line in file:lines() do
            print ("****" .. line)
            time1, value1, value2, time2, pen1, pen2 = string.match(line, "^([a-z-]*)[ ]*([0-9]*)[ ]*([0-9]*)[ ]*([a-z-]*)[ ]*([0-9]*)[ ]*([0-9]*)$")
			if (time1 ~= nil) then
                local img1 = canvas:new(("../media/bandeiras-legendas/" .. time1 .. ".gif"))
                local img2 = canvas:new(("../media/bandeiras-legendas/" .. time2 .. ".gif"))
                if i < 4 then
                    canvas:compose(532, (29 + i*89), img1)
                    canvas:compose(532, (29 + 45 + i*89), img2)
                    canvas:drawText(493, (31 + i*89), value1)
                    canvas:drawText(493, (31 + 43 + i*89), value2)
                    if (pen1 ~= null and pen1 ~= "") then
                    	canvas:attrFont('vera',20,'normal')
                    	canvas:drawText(500, (31 + i*89), pen1)
                    	canvas:drawText(500, (31 + 43 + i*89), pen2)
                    	canvas:attrFont('vera',26,'bold')
                    end
                elseif i > 3 and i < 6 then
                    canvas:compose(376, (56 + (i - 4)*177), img1)
                    canvas:compose(376, (56 + 89 + (i - 4)*177), img2)
                    canvas:drawText(346, (56 + (i - 4)*175), value1)
                    canvas:drawText(346, (56 + 89 + (i - 4)*175), value2)
                    if (pen1 ~= null and pen1 ~= "") then
                		canvas:drawText(350, (54 + (i - 4)*175), pen1)
                    	canvas:drawText(350, (54 + 89 + (i - 4)*175), pen2)
                	end
                elseif i < 7 then
                    canvas:compose(220, 146, img1)
                    canvas:compose(210, 233, img2)
                    canvas:drawText(210, 146, value1)
                    canvas:drawText(200, 233, value2)
                    if (pen1 ~= null and pen1 ~= "") then
                		canvas:drawText(230, 144, pen1)
                    	canvas:drawText(230, 230, pen2)
                	end
                else
                    canvas:compose(54, 191, img1)
                    canvas:drawText(12, 191, value1)
                    if (pen1 ~= null and pen1 ~= "") then
                		canvas:drawText(10, 178, pen1)
                	end
                end
            end            
            i = i + 1
            canvas:flush()
        end
        file:close()
    else 
        print (err)
    end
end

redraw()